package com.lvt.example.thinking.in.spring.injection;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * desc：自动 Constructor 注入
 *
 * @author LT
 * @date 2022/4/1
 */
public class AutoWringByNameDependencyConstructorDemo {

    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

        String xmlResourcePath = "classpath:/META-INF/autowring-dependency-injection-constructor.xml";
        xmlBeanDefinitionReader.loadBeanDefinitions(xmlResourcePath);

        // 依赖查找并且创建bean
        UserHolder userHolder = beanFactory.getBean(UserHolder.class);
        System.out.println(userHolder);
    }
}
